package com.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.crm.common.ResVo;
import com.crm.entity.NewsCategory;
import com.crm.service.NewsCategoryService;
import com.spring4all.swagger.EnableSwagger2Doc;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@EnableSwagger2Doc
@RequestMapping("/newsCategory")
@Api(tags = "新闻类别管理")
public class NewsCategoryController {

	@Autowired
	private NewsCategoryService newsCategoryService;
	
	
	@GetMapping("/getNewsCategory")
	@ApiOperation("获取新闻所有分类")
	public ResVo<Object> getNewsCategory() {
		List<NewsCategory> message = newsCategoryService.getNewsCategory();
		return ResVo.success(message);
	}
	
	@GetMapping("/getNewsCategory/{pageIndex}")
	@ApiOperation("按条件获取新闻分类")
	public ResVo<Object> getNewsCategoryBycategory(@RequestParam(value="category", required = false) @ApiParam("分类名") String category,@PathVariable("pageIndex") @ApiParam("页码") Integer pageIndex) {
		Page<NewsCategory> message = newsCategoryService.getNewsCategoryBycategory(category,pageIndex);
		return ResVo.success(message);
	}
	
	@PostMapping("/addNewsCategory")
	@ApiOperation("添加新闻类别")
	public ResVo<Object> addNewsCategory(@RequestBody NewsCategory newsCategory){
		newsCategoryService.addNewsCategory(newsCategory);
		return ResVo.defaultSuccess();
	}
	
	
	
}
